#pragma once

#include <iostream>

#include "LogFormatter.h"
#include "LogEvent.h"

namespace bamboo {
    
//日志输出地
class LogAppender {
public:
    typedef std::shared_ptr<LogAppender> ptr;
    virtual ~LogAppender() {}

    virtual void log(LogEvent::ptr event) {}

    void setFormatter(LogFormatter::ptr val) { m_formatter = val; }
    LogFormatter::ptr getFormatter() {return m_formatter;}

protected:
    LogFormatter::ptr m_formatter;
};

//输出到控制台的Appender
class StdoutLogAppender : public LogAppender {
public:
    typedef std::shared_ptr<StdoutLogAppender> ptr;

    virtual void log(LogEvent::ptr event);
};

//定义输出到文件的Appender
class FileLogAppender : public LogAppender {
public:
    typedef std::shared_ptr<FileLogAppender> ptr;

    FileLogAppender(const std::string& filename);

    virtual void log(LogEvent::ptr event);

    void reopen();

private:
    std::string m_filename;
    //std::ofstream m_filestream;
};

} // namespace bamboo